package com.nine.system.controller;


import cn.dev33.satoken.annotation.SaCheckRole;
import com.nine.system.service.AuditService;
import com.nine.common.tool.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Description:
 * @ClassName: auditController
 * @Author: luodeng
 * @Date: 2023/6/6 9:15
 * @Version: 1.0
 */
@RestController
@RequestMapping("/audit")
@Api(tags = "平台审核Api",description = "平台进行审核的所有api")
public class AuditController {


    @Autowired
    private AuditService auditService;


    @ApiOperation(value = "提交工程师申请")
    @ApiImplicitParams({
            @ApiImplicitParam(value="姓名",name="auditName",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="手机号",name="auditPhone",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="个人描述",name="auditDescription",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="工作经验",name="auditExperience",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="身份信息",name="auditIdcard",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="省份",name="auditProvince",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="市区",name="auditCity",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="区县",name="auditArea",dataType="String",dataTypeClass = String.class, paramType = "query")
    })
    @PostMapping(value = "/admit", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ResponseResult add(
                              @RequestParam("auditName") String auditName,
                              @RequestParam("auditPhone") String auditPhone,
                              @RequestParam("auditDescription")String auditDescription,
                              @RequestParam("auditExperience") String auditExperience,
                              @RequestParam("auditIdcard") MultipartFile auditIdcard,
                              @RequestParam("auditProvince")String auditProvince,
                              @RequestParam("auditCity")String auditCity,
                              @RequestParam("auditArea")String auditArea

    ){
        return auditService.admit(auditName,auditPhone,auditDescription,auditExperience,auditIdcard,auditProvince,auditCity,auditArea);
    }


    @SaCheckRole("101")
    @ApiOperation(value = "101处理工程师申请单")
    @ApiImplicitParams({
            @ApiImplicitParam(value="申请单ID",name="id",dataType="Integer",dataTypeClass = Integer.class, paramType = "path"),
            @ApiImplicitParam(value="处理结果(1为通过/2为拒绝)",name="result",dataType="Integer",dataTypeClass = Integer.class,paramType = "path")
    })
    @GetMapping("/handleAudit/{id}/{result}")
    public ResponseResult handleAudit(@PathVariable int id,@PathVariable int result){
        return auditService.handleAudit(id,result);
    }


    @SaCheckRole("101")
    @ApiOperation(value = "101查看某个具体工程师申请单")
    @ApiImplicitParam(value = "工程师申请单ID",name = "id",dataType = "Integer",dataTypeClass = Integer.class,paramType = "path")
    @GetMapping("/{id}")
    public ResponseResult getOne(@PathVariable int id){
        return auditService.getOne(id);
    }


    @ApiOperation(value = "查看经过筛选的工程师申请单")
    @ApiImplicitParams({
            @ApiImplicitParam(value="审核状态",name="auditStatus",dataType="String",dataTypeClass = String.class, paramType = "query"),
            @ApiImplicitParam(value="当前页",name="page",dataType="Integer",dataTypeClass = Integer.class,paramType = "query"),
            @ApiImplicitParam(value="每页数据量",name="limit",dataType="Integer",dataTypeClass = Integer.class,paramType = "query")
    })
    @PostMapping("/find")
    public ResponseResult find(@RequestParam("auditStatus") String auditStatus,
                               @RequestParam("page")int page,
                               @RequestParam("limit")int limit){
        return auditService.find(auditStatus,page,limit);
    }

    @ApiOperation(value = "查看数据库中未审核的工程师申请单")
    @ApiImplicitParams({
            @ApiImplicitParam(value="当前页",name="page",dataType="Integer",dataTypeClass = Integer.class,paramType = "path"),
            @ApiImplicitParam(value="每页数据量",name="limit",dataType="Integer",dataTypeClass = Integer.class,paramType = "path")
    })
    @GetMapping("/getWork")
    public ResponseResult getWork(int page, int limit){
        return auditService.getWork(page, limit);
    }


    @SaCheckRole("101")
    @ApiOperation(value = "工程师申请单的各个状态统计")
    @GetMapping("/getPie")
    public ResponseResult getAuditStatusCount(){
        return auditService.getAuditStatusCount();
    }


    @SaCheckRole("101")
    @ApiOperation(value = "101获取没有处理的工程师信息更正申请")
    @GetMapping("/getUnhandleChanges")
    public ResponseResult getHandleChanges(int page,int limit){
        return auditService.getUnhandleChanges(page,limit);
    }


    @SaCheckRole("101")
    @ApiOperation(value = "101筛选更正申请接口")
    @PostMapping("/findChanges")
    public ResponseResult findChanges(@RequestParam("auditStatus") String auditStatus,
                               @RequestParam("page")int page,
                               @RequestParam("limit")int limit){
        return auditService.findChanges(auditStatus,page,limit);
    }

    @SaCheckRole("101")
    @ApiOperation(value = "101处理工程师信息更正申请")
    @ApiImplicitParams({
            @ApiImplicitParam(value="更正申请ID",name="id",dataType="Integer",dataTypeClass = Integer.class,paramType = "path"),
            @ApiImplicitParam(value="处理结果(1为同意/2为拒绝)",name="result",dataType="Integer",dataTypeClass = Integer.class,paramType = "path")
    })
    @GetMapping("/handleChange/{id}/{result}")
    public ResponseResult handleChange(@PathVariable int id,@PathVariable int result){
        return auditService.handleChange(id,result);
    }

    @SaCheckRole("101")
    @ApiOperation(value = "101统计工程师信息更改申请状态")
    @GetMapping("/getChangePie")
    public ResponseResult getChangePie(){
        return auditService.getChangePie();
    }
}
